#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool evaluateTree(TreeNode* root) {
        if (root->right == nullptr)
        {
            return root->val;
        }
        int left = evaluateTree(root->left);
        int right = evaluateTree(root->right);
        if (root->val == 2)
        {
            if (left == 0 && right == 0)
            {
                root->val = 0;
            }
            else
            {
                root->val = 1;
            }
        }
        else
        {
            if (left == 1 && right == 1)
            {
                root->val = 1;
            }
            else
            {
                root->val = 0;
            }
        }
        return root->val;


    }
};